#!bin/bash
#This fiber_num
exsig=0
while true;
do 
    echo ""
    echo "---------欢迎使用本系统----------"
    echo "    1. 上班签到"
    echo "    2. 下班签到"
    echo "    3. 考勤信息查询"
    echo "    4. 退出系统"
    echo "---------------------------------"
    echo ""
    echo "请输入你的选项:"
    read choice
    case $choice in
        1)echo "请输入你的名字:"
            read name
            echo "请输入你的密码:"
            read password
            if test -r/home/user_01/userinfo.dat 
            then
                while read fname fpassword
                do 
                    echo "$fname"
                    echo "$fpassword"
                    if test "$fname" = "$name"
                    then 
                        break
                    fi 
                done </home/user_01/userinfo.dat 
            else
                echo System Error:userinfo.dat does not exist!
            fi 
            if test "$fname" != "$name"
            then 
                echo "不存在该用户!"
            elif test "$fpassword" != "$password"
            then 
                echo "密码不正确!"
            else 
                hour=`date +%H`
                if test "$hour" -gt 8
                then 
                    echo "你迟到了!"
                    echo "$name 上班迟到---日期:`date`" >> /home/user_01/check.dat 
                else 
                    echo "早上好,$name!"
                fi 
            fi
            ;;

        2)  echo "请输入你的名字:"
            read name
            echo "请输入你的密码:"
            read password
            if test -r/home/user_01/userinfo.dat 
            then
                while read fname fpassword
                do 
                    if test "$fname" = "$name"
                    then 
                        break
                    fi 
                done </home/user_01/userinfo.dat 
            else
                echo System Error:userinfo.dat does not exist!
            fi 
            if test "$fname" != "$name"
            then 
                echo "不存在该用户!"
            elif test "$fpassword" != "$password"
            then 
                echo "密码不正确!"
            else 
                hour=`date +%H`
                if test "$hour" -lt 18
                then 
                    echo "你早退了!"
                    echo "$name 上班早退---日期:`date`" >> /home/user_01/check.dat 
                else 
                    echo "再见,$name!"
                fi 
            fi
            ;;
        3)  echo "请输入你的名字:"
            read name
            echo "请输入你的密码:"
            read password
            if test -r/home/user_01/userinfo.dat 
            then
                while read fname fpassword
                do 
                    if test "$fname" = "$name"
                    then 
                        break
                    fi 
                done </home/user_01/userinfo.dat 
            else
                echo System Error:userinfo.dat does not exist!
            fi 
            if test "$fname" != "$name"
            then 
                echo "不存在该用户!"
            elif test "$fpassword" != "$password"
            then 
                echo "密码不正确!"
            else
                echo "你的记录:"
                echo "----------------------"
                cat -b /home/user_01/check.dat | grep $name 
                echo "----------------------"
            fi 
            ;;
        4)echo "欢迎你的使用,再见!"
            exist=1
            ;;
        *)echo "请输入合法的选项!"
            ;;
    esac
    if test "exist"="1"
    then 
        break 
    fi 
done 

#end
